package org.example;

import java.util.*;

public class Main {
    public static void main(String[] args) {
//        double a = 2.2d;
//        int[] arr = new int[2]{1,2};
//        a *= a;
//        System.out.println(a);
//        Queue<int[]> queue = new LinkedList<>();
//        String s = "1134defAV";
//        s = s.toLowerCase();
//        System.out.println(s);
//        String s = "race a car";
//        isPalindrome(s);
//        StringBuilder str = new StringBuilder();
        Integer a = 1;
        int b = 1;

    }

    public static boolean isPalindrome(String s) {
        int left = 0, right = s.length() - 1;
        s = s.toLowerCase();
        while(left < right)
            char c_left = s.charAt(left);
            if(c_left >= 'z' || c_left <= 'a'){
                left++;
                continue;
            }
            char c_right = s.charAt(right);
            if(c_right >= 'z' || c_right <= 'a'){
                right--;
                continue;
            }
            if(c_left != c_right){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }

    public static int myAtoi(String s) {
        int i = 0, len = s.length();
        int flag = 1;
        while(i < len){
            char c = s.charAt(i);
            if(c == ' ' || c == '0'){
                i++;
                continue;
            }else if(c == '-'){
                flag *= -1;
            }else if(c == '+'){
                ;
            }else if(c >= '1' && c <= '9'){
                break;
            }else{
                return 0;
            }
        }
        if(i == len){
            return 0;
        }
        int[] ret = new int[10];
        int index = 0;
        while(i < len){
            char c = s.charAt(i);
            i++;
            if(c >= '0' && c <= '9'){
                ret[index++] = c - '0';
            }else if(c == ' '){
                continue;
            }else{
                break;
            }
        }
        int sum = 0;
        int mul = 0;
        while(index != 0){
            sum += Math.pow(10, mul) * ret[index - 1];
            mul++;
            index--;
        }
        return sum * flag;
    }

    public static String minWindow(String s, String t) {
        int[] tmap = new int[26];
        int[] smap = new int[26];
        int[] ret = new int[2];
        int min = Integer.MAX_VALUE;
        int left = 0, right = 0;
        for(int i = 0; i < t.length(); i++){
            tmap[t.charAt(i) - 'A']++;
        }
        int len = s.length();
        while(right < len){
            while(!contains(smap, tmap)){
                smap[s.charAt(right) - 'A']++;
                right++;
            }
            while(smap[s.charAt(left) - 'A'] > tmap[s.charAt(left) - 'A']){
                smap[s.charAt(left) - 'A']--;
                left++;
            }
            if(min > right - left){
                min = right - left;
                ret[0] = left;
                ret[1] = right;
            }
            smap[s.charAt(left) - 'A']--;
            left++;
        }
        return s.substring(left - 1, right);
    }

    public static boolean contains(int[] arr, int[] arr2){
        for(int i = 0; i < 26; i++){
            if(arr[i] < arr2[i]){
                return false;
            }
        }
        return true;
    }

    public static void rotate(int[] nums, int k) {
        int len = nums.length;
        k %= len;
        if(k == 0){
            return;
        }
        int[] tmp = new int[len];
        int index = len - k;
        int n = 0;
        while(n < len){
            tmp[n++] = nums[index % len];
            index++;
        }
        for(int i = 0; i < len ; i++){
            nums[i] = tmp[i];
        }
    }
}